;;(load "rew.scm")
(define-macro/err (rewrite-lisp-func/aux sexp cyl)
  `(let* ((cur-cyl ,cyl)
	  (cur-unit (nth 0 cur-cyl))
	  (cur-typ (nth 3 cur-cyl))
	  )
     ;;(y-or-n "sexp->rewrite TEST:guide=~a,cur-unit=~a,cur-typ=~a,cyl-l=~a.\n" cyl-sexp-guide cur-unit cur-typ cyl-l)
     (cond
      ((eq? cyl-sexp-guide 'lisp-quote)
       (run/err rewrite-cyl/quote cur-cyl))
      ;;condition for if the first parameter:only cyl-l has 1 unit and is lisp-begin.
      ((eq? cyl-sexp-guide 'lisp-unquote)
       (run/err rewrite-cyl/unquote cur-cyl))
      ((and (pair? cyl-l)(= (length cyl-l) 1)(eq? (nth 3 (nth 0 cyl-l)) 'lisp-begin))
       (cond
	;;rule:it must be ciyu after lisp-begin.
	((and (string? cur-unit)(eq? cur-typ '词语))
	   (let* ((cur-coding-l (find-dict-coding-list cur-unit 'system))
		  (cur-coding (if cur-coding-l (nth 1 cur-coding-l) #f)) ;;(handle-new-lisp-func/aux)
		  (cur-lisp-type (if cur-coding-l (nth 0 cur-coding-l) #f))
		  )
	     (cond
	      ((and cur-coding (eq? cur-lisp-type 'lisp系统函数))
	       (list cur-unit (string-length cur-unit) cur-coding cur-lisp-type (cyl-serial)))
	      (else
	       (err-msg "sexp->rewrite-lisp-func/aux:[~a]没有作为lisp 系统函数定义，请添加该函数定义。" cur-unit)
	       (set-car! (list-tail cur-cyl 3) 'lisp函数)
	       (set! cur-coding (append-new-coding cur-unit 'lisp函数 #f))
	       (set-car! (list-tail cur-cyl 2) cur-coding)
	       (if (not (search-dict-member cur-unit cyl-undefined-symbol-list))
		   (push (list cur-unit cur-coding '未定义函数 'lisp函数 cyl-current-define-function-name) cyl-undefined-symbol-list))
	       cur-cyl
	       )
	      )
	     ))
	(else
	 ;;(exit-sexp (list 'err i (merge-num i ,cyl 1) '非法语法 (err-format 'sexp->rewrite-sexp-func/aux i "lisp调用的第一项[~a]不是lisp 系统函数。" cur-unit)))
	 cur-cyl
	 )))
      (else
       ;;(y-or-n "rewrite-lisp-func/aux000:cur-cyl=~a\n" cur-cyl)
       (let ((tmp-cyl (list cur-cyl)))
	 (set! tmp-cyl (rewrite-cyl/pure-yexp->syntax tmp-cyl))
	 (nth 0 tmp-cyl))
       ))))
(define (rewrite-cyl/quote cur-cyl)
  ;;(y-or-n "rewrite-cyl/quote:cur-cyl=~a\n" cur-cyl)
  (let ((cur-unit (nth 0 cur-cyl))
	(cur-typ (nth 3 cur-cyl))
	)
    (if (and (string? cur-unit)(eq? cur-typ '词语))
	(begin
	  (set-car! (list-tail cur-cyl 3) '符号常量)
	  (set-car! (list-tail cur-cyl 2) 0)
	  cur-cyl
	  )
	cur-cyl
	)
    ))
(define (rewrite-cyl/unquote cur-cyl)
  ;;(y-or-n "rewrite-cyl/unquote:cur-cyl=~a\n" cur-cyl)
  (let ((tmp-cyl (list cur-cyl)))
    (set! tmp-cyl (rewrite-cyl/pure-yexp->syntax tmp-cyl))
    (nth 0 tmp-cyl))
  )
